import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import swal, { SweetAlertType } from 'sweetalert2';

@Component({
  selector: 'app-c-btn-tool',
  templateUrl: './c-btn-tool.component.html',
  styleUrls: ['./c-btn-tool.component.less']
})
export class CBtnToolComponent implements OnInit {

    @Output() onChange = new EventEmitter<any>();
    @Output() onChangeTxt = new EventEmitter<any>();
    @Output() onDelete = new EventEmitter<any>();

    targetData;

    _rightText;
    @Input() rightData;

    set rightText(value){
        this.rightData.text = value;
        this.onChangeTxt.emit(this.rightData);
    }

    get rightText(){
        if (!this.rightData.text) {
            return '按钮名称';
        } else {
            return this.rightData.text;
        }

    }

    _rightStyleX;
    @Input()
    set rightStyleX(value){
        this._rightStyleX = value;
        this.emitXYWH();
    }

    get rightStyleX(){
        return this._rightStyleX;
    }

    _rightStyleY;
    @Input()
    set rightStyleY(value){
        this._rightStyleY = value;
        this.emitXYWH();
    }

    get rightStyleY(){
        return this._rightStyleY;
    }

    _rightStyleW;
    @Input()
    set rightStyleW(value){
        this._rightStyleW = value;
        this.emitXYWH();
    }

    get rightStyleW(){
        return this._rightStyleW;
    }

    _rightStyleH;
    @Input()
    set rightStyleH(value){
        this._rightStyleH = value;
        this.emitXYWH();
    }

    get rightStyleH(){
        return this._rightStyleH;
    }



    constructor() { }

    ngOnInit() {
        this.targetData = [
            {value: 'sceneA', label: '场景A'},
            {value: 'sceneB', label: '场景B'},
            {value: 'sceneC', label: '场景C'},
            {value: 'sceneD', label: '场景D'}
        ];
        this.rightData.target = this.targetData[0];
    }

    emitXYWH() {
        this.onChange.emit({
            x: this._rightStyleX,
            y: this._rightStyleY,
            width: this._rightStyleW,
            height: this._rightStyleH
        });
    }

    deleteComponent() {
        this.onDelete.emit();
    }

    save() {
        swal(`保存成功`, '', 'info');
    }
}
